package com.examination.utils;

import java.io.IOException;
import java.sql.*;
import java.util.Properties;

public class PropertiesUtil {
    static Properties pros = null;  //可以帮助读取和处理资源文件中的信息
    static {    //加载JDBCUtil类的时候调用
        pros = new Properties();
        try {
            pros.load(Thread.currentThread().getContextClassLoader().getResourceAsStream("application.properties"));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /**
     * 获得数据库的链接对象
     * @return
     */
    public static Connection getMysqlConn(){
        try {
            Class.forName(pros.getProperty("mysqlDriver"));
            return DriverManager.getConnection(pros.getProperty("mysqlURL"),
                    pros.getProperty("mysqlUser"),pros.getProperty("mysqlPwd"));
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }


}
